package com.cyw.generator.com.controller;

import com.xiaohai.generator.common.domain.PageEntity;
import com.xiaohai.generator.common.domain.JsonBean;
import com.xiaohai.generator.common.domain.ResultCode;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.*;
import com.cyw.generator.com.service.ITbGraphRelationService;
import com.cyw.generator.com.entity.TbGraphRelation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Cyw
 * @since 2022-09-28
 */
@Api(tags = {""})
@RestController
@RequestMapping("/com/tb-graph-relation")
public class TbGraphRelationController {

    private final Logger log = LoggerFactory.getLogger(getClass());
    @Resource
    private ITbGraphRelationService tbGraphRelationService;


    @ApiOperation(value = "新增")
    @PostMapping()
    public JsonBean add(@RequestBody TbGraphRelation tbGraphRelation){
        try {
            return tbGraphRelationService.add(tbGraphRelation);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return JsonBean.returnResponse(false, ResultCode.SERVICE_ERR);
        }
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("{id}")
    public JsonBean delete(@PathVariable("id") Long id){
        try {
            return tbGraphRelationService.delete(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return JsonBean.returnResponse(false, ResultCode.SERVICE_ERR);
        }
    }

    @ApiOperation(value = "更新")
    @PutMapping()
    public JsonBean update(@RequestBody TbGraphRelation tbGraphRelation){
        try {
            return tbGraphRelationService.updateData(tbGraphRelation);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return JsonBean.returnResponse(false, ResultCode.SERVICE_ERR);
        }
    }

    @ApiOperation(value = "id查询")
    @GetMapping("{id}")
    public JsonBean findById(@PathVariable Long id){
        try {
            return tbGraphRelationService.findById(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return JsonBean.returnResponse(false, ResultCode.SERVICE_ERR);
        }
    }

    @ApiOperation(value = "查询列表/分页数据")
    @GetMapping()
    public JsonBean findListByPage(PageEntity page,TbGraphRelation tbGraphRelation){
        try {
            return tbGraphRelationService.findListByPage(page,tbGraphRelation);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return JsonBean.returnResponse(false, ResultCode.SERVICE_ERR);
        }
    }
    }
